/* GUI CONVERTED from rcrp10.p (converter v1.76) Wed May 15 09:49:19 2002 */
/* rcrp10.p - Release Management Customer Schedules                     */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/* $Revision: 1.9.1.3 $                                                     */
/*V8:ConvertMode=Report                                                 */
/* REVISION: 7.3    LAST MODIFIED: 12/01/92           BY: WUG *G462*    */
/* REVISION: 7.3    LAST MODIFIED: 05/07/93           BY: WUG *GA80*    */
/*                                   10/12/93   by: jzs *GG27*          */
/* REVISION: 7.3    LAST MODIFIED: 11/01/94           BY: ame *GN84*    */
/* REVISION: 8.5    LAST MODIFIED: 02/20/97  BY: *J1JB* Patrick Rowan   */
/* REVISION: 8.5    LAST MODIFIED: 04/07/97  BY: *J1M3* Jean Miller     */
/* REVISION: 8.6E   LAST MODIFIED: 02/23/98  BY: *L007* A. Rahane       */
/* REVISION: 8.6E   LAST MODIFIED: 10/04/98  BY: *J314* Alfred Tan      */
/* REVISION: 9.1    LAST MODIFIED: 03/24/00  BY: *N08T* Annasaheb Rahane */
/* REVISION: 9.1    LAST MODIFIED: 08/12/00  BY: *N0KP* myb              */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* $Revision: 1.9.1.3 $    BY: Katie Hilbert         DATE: 05/15/02  ECO: *P06N*  */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
/* SHIPPING LABEL PRINT */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

{mfdtitle.i "2+ "}

define new shared variable ctnr_count   as integer.
define new shared variable label_string as character extent 30.
define shared variable global_recid     as recid.

define variable disp_abs_id          as character.
define variable addr                 as character.
define variable addrs                as character extent 5.
define variable addrcount            as integer.
define variable item_count           as integer.
define variable item_number          as character.
define variable cust_item_number     as character.
define variable abs_recid            as recid.
define variable label_type           as character.
define variable barlbl_prt           like ad_barlbl_prt.
define variable current_template_filename as character.
define variable template_data        as character.
define variable label_data           as character.
define variable work_data            as character.
define variable total_qty            as decimal.
define variable total_po             as decimal.
define variable po_number            as character.
define variable shipper_id           as character.
define variable ad_mixed_fn          as character.
define variable ad_master_fn         as character.
define variable ad_single_fn         as character.
define variable supplier_id          as character.
define variable shipfrom_name        as character.
define variable shipto_name          as character.
define variable filename             as character.
define variable char1                as character.
define variable char2                as character.
define variable i                    as integer.
define variable ii                   as integer.
define variable j                    as integer.
define variable label_from           as integer format ">>9"
                                     label "Label Number".
define variable label_to             as integer format ">>9" label "To".
define variable shipto_id            as character.
define variable using_default_labels like mfc_logical initial no.
define stream template.


/*GUI preprocessor Frame A define */
&SCOPED-DEFINE PP_FRAME_NAME A

FORM /*GUI*/ 
   
 RECT-FRAME       AT ROW 1 COLUMN 1.25
 RECT-FRAME-LABEL AT ROW 1 COLUMN 3 NO-LABEL VIEW-AS TEXT SIZE-PIXELS 1 BY 1
 SKIP(.1)  /*GUI*/
abs_shipfrom           colon 28 label "Ship-From Site"
   si_desc                at 45 no-label
   abs_id                 colon 28 label "Container ID"
   skip(1)
   label_from             colon 28
   label_to               colon 47
   skip
with frame a side-labels width 80 attr-space NO-BOX THREE-D /*GUI*/.

 DEFINE VARIABLE F-a-title AS CHARACTER INITIAL "".
 RECT-FRAME-LABEL:SCREEN-VALUE in frame a = F-a-title.
 RECT-FRAME-LABEL:HIDDEN in frame a = yes.
 RECT-FRAME:HEIGHT-PIXELS in frame a =
  FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.
 RECT-FRAME:WIDTH-CHARS IN FRAME a = FRAME a:WIDTH-CHARS - .5.  /*GUI*/

/*GUI preprocessor Frame A undefine */
&UNDEFINE PP_FRAME_NAME



/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).

define new shared workfile work_abs_mstr like abs_mstr.
find first soc_ctrl no-lock.

find abs_mstr where recid(abs_mstr) = global_recid no-lock no-error.

if available abs_mstr and abs_id begins "c" and abs_type = "s" then do:
   find si_mstr where si_site = abs_shipfrom no-lock.

   display
      abs_shipfrom
      si_desc
      substring(abs_id,2,50) @ abs_id
   with frame a.
end.

repeat:
   do with frame a:
      prompt-for
         abs_shipfrom
         abs_id
      editing:

         global_site = input abs_shipfrom.

         if frame-field = "abs_shipfrom" then do:
            {mfnp05.i abs_mstr abs_id
               "abs_id begins ""c"" "
               abs_shipfrom
               "input abs_shipfrom"}
            if recno <> ? then do:
               find si_mstr where si_site = abs_shipfrom no-lock no-error.

               assign
                  disp_abs_id = substring(abs_id,2).

               display
                  abs_shipfrom
                  si_desc when (available si_mstr)
                  ""      when (available si_mstr) @ si_desc
                  disp_abs_id @ abs_id.
            end.
         end.
         else
            if frame-field = "abs_id" then do:
            {mfnp05.i abs_mstr abs_id
               "abs_shipfrom = input abs_shipfrom and abs_id begins ""c"""
               abs_id
               " ""c"" + input abs_id"}
            if recno <> ? then do:
               find si_mstr where si_site = abs_shipfrom no-lock no-error.

               assign
                  disp_abs_id = substring(abs_id,2).

               display
                  abs_shipfrom
                  si_desc when (available si_mstr)
                  ""      when (available si_mstr) @ si_desc
                  disp_abs_id @ abs_id.
            end.
         end.
         else do:
            status input.
            readkey.
            apply lastkey.
         end.
      end.
   end.

   find abs_mstr where abs_shipfrom = input abs_shipfrom
      and abs_id = "c" + input abs_id no-lock no-error.
   if not available abs_mstr then do:
      /* Container number does not exist */
      {pxmsg.i &MSGNUM=763 &ERRORLEVEL=3}
      undo, retry.
   end.

   abs_recid = recid(abs_mstr).

   find si_mstr where si_site = abs_shipfrom no-lock no-error.

   if not available si_mstr then do:
      /* Site does not exist */
      {pxmsg.i &MSGNUM=708 &ERRORLEVEL=3}
      undo, retry.
   end.

   assign
      disp_abs_id = substring(abs_id,2).

   display
      abs_shipfrom
      si_desc
      disp_abs_id @ abs_id
   with frame a.

   if substring(abs_status,1,1) = "y" then do:
      /* Label has been printed already */
      {pxmsg.i &MSGNUM=8120 &ERRORLEVEL=2}
   end.

   /* IF QUANTITY IS > 1 THEN WE  NEED  TO  ASK  THEM  THE  LABEL
   NUMBER  RANGE  TO  PRINT  OTHERWISE JUST ONE LABEL IS PRINTED.
   LABEL NUMBERS ARE IN THE RANGE 001 TO THE  CONTAINER  QUANTITY
   THEY  ENTERED FOR THIS RECORD.  THIS ALLOWS THE USER TO CREATE
   A ZILLION LABELS WITHOUT HAVING TO CREATE A ZILLION  CONTAINER
   RECORDS.  */

   assign
      label_from = 1
      label_to   = max(1,abs_qty).

   display
      label_from
      label_to
   with frame a.

   if abs_qty > 1 then do on error undo, retry:
      set label_from label_to with frame a.

      if label_to > abs_qty then do:
         /* Value entered is greater than container total */
         {pxmsg.i &MSGNUM=8125 &ERRORLEVEL=3}
         next-prompt label_to with frame a.
         undo, retry.
      end.
   end.

   /* CHASE SHIP-TO INFORMATION FOR LATER PROCESSING */
   /* The Enhanced Shipper handles the ship-to
   information differently than standard product.
   Container Workbench allows containers to be created
   w/o being pre-assigned to a customer (i.e., ship-to).
   Therefore, no ship-to is stored within container records
   built w/Container Workbench.  Ship-to is stored in the
   shipper or pre-shipper records when built with the
   Shipper Workbench.  Also, the ship-to information is
   only stored in the shipper record and does not cascade
   down to the container records.

   In order to print container labels that were created
   using Container WB, the shipper id loop was moved here and
   enhanced to find ship-to information while looking
   for the shipper id.  Once the shipper record is found
   the ship-to value will be used to retrieve customer
   information.  If no ship-to value could be found, then
   defaults are used to produce the shipping labels.

   The standard product differs from the Container WB in that
   All container records have ship-to values, because it
   is a required when creating container and  sub-containers. */

   /* CHASE PARENTS TO GET THE SHIPPER ID IF THERE IS ONE */
   assign
      shipper_id = ""
      shipto_id = "".
   run get_parent
      (recid(abs_mstr),
      output shipper_id,
      output shipto_id).

   /* DETERMINE SHIPPING LABELS AND INITIALIZE VARIABLES  */

   if shipto_id = "" then
      assign
         using_default_labels    = yes
         cust_item_number        = ""
         shipto_name             = ""
         barlbl_prt              = ""
         ad_mixed_fn             = ""
         ad_master_fn            = ""
         ad_single_fn            = ""
         addrcount               = 0
         addrs                   = "".
   else
      using_default_labels = no.

   /* GET ALL ADDRESS IDENTIFIERS IN THE HIERARCHY */

   /* RETRIEVE THE ADDRESS IDENTIFIERS FOR THOSE CONTAINERS
   THAT HAVE BEEN ASSIGNED TO A SHIPPER.
   TEST FOR USING DEFAULT LABEL TEMPLATES. */

   if using_default_labels = no then do:
      addrcount = 1.
      find ad_mstr where ad_addr = shipto_id no-lock.
      addrs[addrcount] = ad_addr.

      do while available ad_mstr and ad_ref > "":
         assign
            addrcount = addrcount + 1
            addrs[addrcount] = ad_ref
            addr = ad_ref.
         find ad_mstr where ad_addr = addr no-lock no-error.
      end.
   end.

   /* PICK UP LABEL SETUP DATA */

   /* RETRIEVE SHIP-TO/CUSTOMER LABEL TEMPLATE FILENAMES FROM THE
      ADDRESS MASTER FOR THOSE CONTAINERS THAT ARE NOT
      USING THE DEFAULT SHIPPING LABELS.  */

   if using_default_labels = no then do:
      find ad_mstr where ad_addr = shipto_id no-lock.
      barlbl_prt = ad_barlbl_prt.

      if barlbl_prt = "" then do:
         /* Shipping label template files have not been set up */
         {pxmsg.i &MSGNUM=8121 &ERRORLEVEL=3}
         undo, retry.
      end.

      assign
         ad_mixed_fn    = trim(substring(barlbl_prt,124,40))
         ad_master_fn   = trim(substring(barlbl_prt,164,40))
         ad_single_fn   = trim(substring(barlbl_prt,204,40))
         .
   end.

   /* PICK UP THE CUSTOMER/SHIPTO'S ID FOR SUPPLIER */

   supplier_id = "".

   do i = 1 to addrcount:
      find qad_wkfl where qad_key1 = "sfst_det"
         and qad_key2 = string(addrs[i],"x(8)") + abs_shipfrom
      no-lock no-error.

      if available qad_wkfl then do:
         supplier_id = qad_charfld[3].
         if qad_charfld[3] = "" then supplier_id = qad_charfld[4].
         leave.
      end.
   end.

   /*
   EXPLODE CONTAINER TO SEE WHAT TYPE OF LABEL TO PRINT:
   STANDARD (NO SUBCONTAINERS/ONLY ONE SKU)
   MASTER (SUBCONTAINERS WITH ONLY ONE SKU)
   MIXED GROUP (MULTIPLE SKU'S)
   */

   for each work_abs_mstr exclusive-lock:
      delete work_abs_mstr.
   end.

   ctnr_count = 0.
   {gprun.i ""rcrp10a.p"" "(input recid(abs_mstr))"}
   item_count = 0.

   for each work_abs_mstr no-lock break by abs_item:
      if first-of(abs_item) then
         assign
            item_count  = item_count + 1
            item_number = abs_item
            total_qty   = 0.

      total_qty = total_qty + abs_qty.
   end.

   /* DETERMINE TYPE OF LABEL TO PRINT */

   label_type = "".

   if item_count > 1 then
      label_type = "mixed".
   else
      if item_count = 1 then do:
      if ctnr_count >= 1 then
         label_type = "master".
      else
         label_type = "single".
   end.

   if label_type = "" then do:
      /* Container has no item contents.  Label not printed */
      {pxmsg.i &MSGNUM=8122 &ERRORLEVEL=2}
      undo, retry.
   end.

   /* FIND THE TEMPLATE FILE */

   filename = "".

   /* VALIDATE THE LABEL TEMPLATE FILE NAMES FOR THOSE CONTAINERS
      HAVING SHIP-TO LABEL TEMPLATES.  FOR THOSE CONTAINERS USING
      THE DEFAULT LABELS, FIND AND VALIDATE THE DEFAULT TEMPLATE
      FILENAMES DEFINED IN THE Customer Schedules Control File (7.6.24) */

   if label_type = "mixed" then do:
      if using_default_labels = no then do:
         if ad_mixed_fn = "" or search(ad_mixed_fn) = ? then do:
            /* Mixed Label Template does not exist */
            {pxmsg.i &MSGNUM=8300 &ERRORLEVEL=3}
            message ad_mixed_fn.
            undo, retry.
         end.
      end.
      else do:
         find mfc_ctrl where mfc_field = "rcc_barlbl_mixed_fn"
         no-lock no-error.
         if not available mfc_ctrl then do:
            /* Default Mixed Label Template not set up */
            {pxmsg.i &MSGNUM=1722 &ERRORLEVEL=3}
            undo, retry.
         end.
         else do:
            ad_mixed_fn = mfc_char.
            if ad_mixed_fn = "" or search(ad_mixed_fn) = ? then do:
               /*Default Mixed Label Template does not exist */
               {pxmsg.i &MSGNUM=1733 &ERRORLEVEL=3}
               message ad_mixed_fn.
               undo, retry.
            end.
         end.
      end.

      filename = ad_mixed_fn.
   end.  /* if label_type = "mixed" */
   else
   if label_type = "master" then do:
      if using_default_labels = no then do:
         if ad_master_fn = "" or search(ad_master_fn) = ? then do:
            /* Master Label Template does not exist */
            {pxmsg.i &MSGNUM=8301 &ERRORLEVEL=3}
            message ad_master_fn.
            undo, retry.
         end.
      end.
      else do:
         find mfc_ctrl where mfc_field = "rcc_barlbl_master_fn"
         no-lock no-error.
         if not available mfc_ctrl then do:
            /* Default Master Label Template not set up */
            {pxmsg.i &MSGNUM=1731 &ERRORLEVEL=3}
            undo, retry.
         end.
         else do:
            ad_master_fn = mfc_char.
            if ad_master_fn = "" or search(ad_master_fn) = ? then do:
               /* Default Master Label Template does not exist */
               {pxmsg.i &MSGNUM=1734 &ERRORLEVEL=3}
               message ad_master_fn.
               undo, retry.
            end.
         end.
      end.

      filename = ad_master_fn.
   end. /* if label_type = "master" */
   else
   if label_type = "single" then do:
      if using_default_labels = no then do:
         if ad_single_fn = "" or search(ad_single_fn) = ? then do:
            /* Single Label Template does not exist */
            {pxmsg.i &MSGNUM=8302 &ERRORLEVEL=3}
            message ad_single_fn.
            undo, retry.
         end.
      end.
      else do:
         find mfc_ctrl where mfc_field = "rcc_barlbl_single_fn"
         no-lock no-error.
         if not available mfc_ctrl then do:
            /* Default Single Label Template not set up */
            {pxmsg.i &MSGNUM=1732 &ERRORLEVEL=3}
            undo, retry.
         end.
         else do:
            ad_single_fn = mfc_char.
            if ad_single_fn = "" or search(ad_single_fn) = ? then do:
               /* Default Single Label Template does not exist */
               {pxmsg.i &MSGNUM=1735 &ERRORLEVEL=3}
               message ad_single_fn.
               undo, retry.
            end.
         end.
      end.

      filename = ad_single_fn.
   end. /* if label_type = "single" */

   /* GET CUSTOMER ITEM NUMBER */

   /* TEST FOR USING DEFAULT LABEL TEMPLATES.  */

   if using_default_labels = no then do:
      do i = 1 to addrcount:
         find cp_mstr where cp_part = item_number and cp_cust = addrs[i]
         no-lock no-error.

         if available cp_mstr then leave.
      end.

      if not available cp_mstr then do:
         /* Customer/Ship-To item not defined */
         {pxmsg.i &MSGNUM=8163 &ERRORLEVEL=3}
         undo, retry.
      end.

      cust_item_number = cp_cust_part.
   end.

   /* OUTPUT DESTINATION SELECTION */
   {gpselout.i &printType = "printer"
               &printWidth = 80
               &pagedFlag = " "
               &stream = " "
               &appendToFile = " "
               &streamedOutputToTerminal = " "
               &withBatchOption = "no"
               &displayStatementType = 1
               &withCancelMessage = "yes"
               &pageBottomMargin = 6
               &withEmail = "yes"
               &withWinprint = "yes"
               &defineVariables = "yes"}
/*GUI*/ RECT-FRAME:HEIGHT-PIXELS in frame a = FRAME a:HEIGHT-PIXELS - RECT-FRAME:Y in frame a - 2.


   /* GET A PO NUMBER IF THERE IS ONE */

   total_po = 0.
   for each work_abs_mstr no-lock,
       each sod_det
          where sod_nbr = abs_order
            and sod_line = integer(abs_line)
            and sod_contr_id <> "":
      assign
         total_po = total_po + 1
         po_number = sod_contr_id.
   end.

   /* GET ITEM MASTER RECORD */

   find pt_mstr where pt_part = item_number no-lock no-error.

   /* GET SHIP-FROM NAME */

   shipfrom_name = "".
   find ad_mstr where ad_addr = abs_shipfrom no-lock no-error.
   if available ad_mstr then shipfrom_name = ad_name.

   /* GET SHIP-TO EDI ID AND NAME */

   /* TEST FOR USING DEFAULT LABEL TEMPLATES.  */

   if using_default_labels = no then do:
      find ad_mstr where ad_addr = shipto_id no-lock.
      shipto_name = ad_name.
   end.

   label_string = "".

   if label_type > "" then
      assign
         label_string[01] = substring(abs_id,2)
         label_string[02] = shipper_id
         label_string[03] = cust_item_number
         label_string[04] = item_number
         label_string[05] = if available pt_mstr then pt_desc1 else ""
         label_string[06] = string(total_qty)
         label_string[07] = po_number
         label_string[08] = supplier_id
         label_string[09] = shipfrom_name
         label_string[10] = string(abs_nwt)
         label_string[11] = string(abs_gwt)
         label_string[12] = string(ctnr_count)
         label_string[13] = if available pt_mstr then pt_um else ""
         label_string[14] = substring(abs_doc_data[2],1,20)
         label_string[15] = substring(abs_doc_data[2],21,20)
         label_string[16] = substring(abs_doc_data[2],41,20)
         label_string[17] = substring(abs_doc_data[2],61,20)
         label_string[18] = substring(abs_doc_data[2],81,20)
         label_string[19] = substring(abs_doc_data[2],101,20)
         label_string[20] = substring(abs_doc_data[2],121,20)
         label_string[21] = substring(abs_doc_data[2],141,20)
         .

   if filename <> current_template_filename then do:
      template_data = "".
      input stream template from value(search(filename)) no-echo.
      readkey stream template.

      do while lastkey >= 0:
         template_data = template_data + chr(lastkey).
         if lastkey = 13 then template_data = template_data + chr(10).

         readkey stream template.
      end.

      input stream template close.
      current_template_filename = filename.
   end.

   /* GO THRU LABEL DATA AND REPLACE TAGS WITH DATA VALUES AND PRINT */

   do ii = label_from to label_to:
      assign
         work_data = template_data
         label_data = ""
         i = index(work_data,"0000").

      do while i > 0:
         assign
            label_data = label_data + substring(work_data,1,i - 1)
            char1 = substring(work_data,i + 4,1)
            char2 = substring(work_data,i + 5,1).

         if index("0123456789",char1) > 0
            and index("0123456789",char2) > 0
         then do:
            j = integer(substring(work_data,i,6)).

            if j >= 1 and j <= 30 then do:
               label_data = label_data + label_string[j].

               if abs_qty > 1 and j = 1 then
                  /* FOR CONTAINER RECORDS  WHERE  THE  CONTAINER
                     COUNT  >  1,  WE HAVE TO PRINT A LABEL FOR EACH
                     OCCURRENCE BY APPENDING THE  OCCURRENCE  NUMBER
                     ONTO THE ID NUMBER AS STRING("999").  */

                  label_data = label_data + string(ii,"999").
            end.
         end.

         work_data = substring(work_data,i + 6).
         i = index(work_data,"0000").
      end.

      label_data = label_data + work_data.

      put unformatted label_data.
      page.
   end.

   {mfreset.i}
/*GUI*/ {mfgrptrm.i} /*Report-to-Window*/


   /* MARK PRINTED */

   do transaction:
      find abs_mstr where recid(abs_mstr) = abs_recid exclusive-lock.
      substring(abs_status,1,1) = "y".

      assign
         global_recid = recid(abs_mstr).

      release abs_mstr.
   end.
end.

/* Procedure for chasing parent */
PROCEDURE get_parent:
   define input parameter ctr_recid as recid no-undo.
   define output parameter shipperid as character no-undo.
   define output parameter shipto as character no-undo.

   define variable parent_id as character no-undo.
   define buffer abs_mstr_parent for abs_mstr.

   do for abs_mstr_parent:
      find abs_mstr_parent where
         recid(abs_mstr_parent) = ctr_recid no-lock.

      if abs_shipto <> "" then
         shipto = abs_shipto.

      do while available abs_mstr_parent and
            abs_par_id > "" and not abs_id begins "s":
         parent_id = abs_par_id.

         find abs_mstr_parent where
            abs_shipfrom = abs_mstr.abs_shipfrom and
            abs_id = parent_id no-lock no-error.

         if abs_id begins "s" then
            shipperid = substring(abs_id,2,30).

         /* Record shipto_id if it hasn't been found in the chain already*/
         if shipto = "" and abs_shipto <> "" then
            shipto = abs_shipto.
      end.
   end.

END PROCEDURE. /* get_parent */
